package com.aspose.cells;

class zavx {
   public static com.aspose.cells.b.a.d.zm a(com.aspose.cells.b.a.d.zm var0, Encoding var1) throws Exception {
      com.aspose.cells.b.a.d.zh var2 = new com.aspose.cells.b.a.d.zh();
      com.aspose.cells.b.a.d.zo var3 = new com.aspose.cells.b.a.d.zo(var2, var1);
      com.aspose.cells.b.a.d.zn var4 = new com.aspose.cells.b.a.d.zn(var0, var1);
      int var5 = 1;
      int var6 = var4.d();

      char var9;
      for(char var7 = (char)var6; var4.c() != -1; var7 = var9) {
         int var8 = var4.d();
         var9 = (char)var8;
         if ((var7 < '!' || var7 > '~' || var7 == '=') && var7 != '\r' && var7 != '\n' && var7 != ' ') {
            String var10 = com.aspose.cells.b.a.ze.a((long)var7, 16);
            if (var7 < 16) {
               var3.a("=0" + var10);
               var5 += 2;
            } else if (var7 > 127) {
               var3.a(var7);
               ++var5;
            } else {
               var3.a("=" + var10);
               var5 += var10.length();
            }
         } else if (var8 <= -1) {
            var3.a(var7);
         } else {
            var9 = (char)var8;
            if (var7 != '\t' || var9 != '\n' && var9 != '\r') {
               if (var7 != ' ' || var9 != '\n' && var9 != '\r') {
                  var3.a(var7);
               } else {
                  var3.a("=09");
                  var5 += 2;
               }
            } else {
               var3.a("=09");
               var5 += 2;
            }
         }

         if (var7 != '\r' && var7 != '\n') {
            ++var5;
         }

         if (var7 == '\r' && var9 == '\n') {
            var5 = 1;
         }

         if (var5 >= 75) {
            var3.a("=\r\n");
            var5 = 1;
         }
      }

      var3.c();
      var2.b(0L);
      return var2;
   }

   public static com.aspose.cells.b.a.d.zm b(com.aspose.cells.b.a.d.zm var0, Encoding var1) throws Exception {
      com.aspose.cells.b.a.d.zh var2 = new com.aspose.cells.b.a.d.zh();
      com.aspose.cells.b.a.d.zo var3 = new com.aspose.cells.b.a.d.zo(var2, var1);
      com.aspose.cells.b.a.d.zn var4 = new com.aspose.cells.b.a.d.zn(var0, var1);

      while(true) {
         while(true) {
            if (var4.c() == -1) {
               var2.b(0L);
               return var2;
            }

            char var5 = (char)var4.d();
            if (var5 == '=') {
               if (a(var5, var4, var3, var1)) {
                  continue;
               }
               break;
            }

            b(var5, var4, var3, var1);
            break;
         }

         var3.c();
      }
   }

   private static boolean a(char var0, com.aspose.cells.b.a.d.zn var1, com.aspose.cells.b.a.d.zo var2, Encoding var3) throws Exception {
      char var4 = (char)var1.d();
      char var5 = (char)var1.d();
      if (var4 != '\r' || var5 != '\n') {
         if (!a(var4) || !a(var5)) {
            var2.a(var0);
            var2.a(var4);
            var2.a(var5);
            return true;
         }

         StringBuilder var6 = new StringBuilder();
         var6.append(var4);
         var6.append(var5);

         for(var0 = (char)var1.d(); var0 == '='; var0 = (char)var1.d()) {
            var4 = (char)var1.d();
            var5 = (char)var1.d();
            if (var4 != '\r' || var5 != '\n') {
               var6.append(var4);
               var6.append(var5);
            }
         }

         if (!com.aspose.cells.b.a.zr.a(var6).equals("")) {
            if (var0 == '&') {
               var2.a('=');
               var2.a(com.aspose.cells.b.a.zr.a(var6));
            } else {
               var2.a(a(com.aspose.cells.b.a.zr.a(var6), var3.b()));
            }
         }

         b(var0, var1, var2, var3);
      }

      return false;
   }

   private static void b(char var0, com.aspose.cells.b.a.d.zn var1, com.aspose.cells.b.a.d.zo var2, Encoding var3) throws Exception {
      if (var0 == '\r' && (char)var1.d() == '\n') {
         int var4 = var1.d();
         if (var4 != -1) {
            if (var4 == 32) {
               int var5 = var1.d();
               if (var5 != -1 && var5 == 32) {
                  var2.a(' ');
               } else {
                  var2.a('\r');
                  var2.a('\n');
                  if ((char)var5 == '=') {
                     a('=', var1, var2, var3);
                  } else {
                     var2.a((char)var5);
                  }
               }
            } else {
               var2.a('\r');
               var2.a('\n');
               if ((char)var4 == '=') {
                  a('=', var1, var2, var3);
               } else {
                  var2.a((char)var4);
               }
            }
         } else {
            var2.a('\r');
            var2.a('\n');
         }
      } else {
         var2.a(var0);
      }

   }

   private static boolean a(char var0) {
      return var0 >= '0' && var0 <= '9' || var0 >= 'a' && var0 <= 'f' || var0 >= 'A' && var0 <= 'F';
   }

   private static String a(String var0, String var1) {
      if (var0 == null) {
         throw new IllegalArgumentException("hex");
      } else {
         var0 = com.aspose.cells.b.a.zv.a(var0, ",", "");
         var0 = com.aspose.cells.b.a.zv.a(var0, "\n", "");
         var0 = com.aspose.cells.b.a.zv.a(var0, "\\", "");
         var0 = com.aspose.cells.b.a.zv.a(var0, " ", "");
         if (var0.length() % 2 != 0) {
            var0 = var0 + "20";
         }

         byte[] var2 = new byte[var0.length() / 2];

         for(int var3 = 0; var3 < var2.length; ++var3) {
            try {
               var2[var3] = (byte)Short.parseShort(var0.substring(var3 * 2, var3 * 2 + 2), 16);
            } catch (Exception var5) {
               throw new IllegalArgumentException("hex is not a valid hex number!\\r\\nParameter name: \"hex");
            }
         }

         Encoding var6 = Encoding.getEncoding(var1);
         return var6.a(var2);
      }
   }
}
